package com.ray.quartz.controller;


import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.ray.api.service.UcenterApiService;
import com.ray.auth.system.table.entity.Button;
import com.ray.quartz.service.ScheduleJobLogService;
import com.ray.quartz.service.ScheduleJobService;
import com.ray.quartz.table.entity.ScheduleJob;
import com.ray.quartz.table.entity.ScheduleJobLog;
import com.ray.quartz.util.DataGridUtil;
import com.zjhc.flyhong.common.function.operator.LoginUser;
import com.zjhc.flyhong.common.function.operator.PageDto;
import com.zjhc.flyhong.common.web.Result;
import com.zjhc.web.controller.WebController;

/**
 * 类ScheduleJobLogController的功能描述:
 * 定时任务日志
 * @auther hxy
 * @date 2017-08-25 16:20:35
 */
@RestController
@RequestMapping("/quartz/log")
public class ScheduleJobLogController extends WebController{
	
	 @Autowired
	 UcenterApiService ucenterApiService;
	 @Autowired
	 ScheduleJobLogService  scheduleJobLogService;	
	  
	  
	 /**
     * 列表
     * @param model
     * @param actModelEntity
     * @param request
     * @return
     */
    @RequestMapping("view")
    @RequiresPermissions("quartz:task:log")
    public ModelAndView view(String menuId,Long id,ModelAndView modelAndView, HttpServletRequest request){
    	LoginUser user = getLoginUser();
    	Result<Map<String, List<Button>>>  buttonsResult= ucenterApiService.queryUserButtonsWithMenu(user,menuId);
	  	if(buttonsResult.codeSuccess()){
	  		 modelAndView.addObject("buttons", buttonsResult.getData());
	  	}
	  	modelAndView.addObject("id", id);
	  	modelAndView.setViewName("quartz/task/log");
        return modelAndView;
    }
    
    /**
     * 列表
     * @param model
     * @param params
     * @param request
     * @return
     */
    @RequestMapping("query")
    @RequiresPermissions("quartz:task:log")
    @ResponseBody
    public ResponseEntity<Map<String,Object>> query(Model model,ScheduleJobLog params, HttpServletRequest request){
    	LoginUser user = getLoginUser();
    	PageDto<ScheduleJobLog> pageDto= this.createJQPage(request);
 		List<ScheduleJobLog> jobList = scheduleJobLogService.queryList(pageDto,params);
 		int total = scheduleJobLogService.queryTotal(params);
 		pageDto.setRecords(jobList);
 		pageDto.setTotal(total);
 		return doSuccess(DataGridUtil.dataConvert(pageDto));
    }
}
